package cn.iocoder.yudao.module.system.controller.admin.curingemperature;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.system.controller.admin.curingemperature.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.curingemperature.CuringEmperatureDO;
import cn.iocoder.yudao.module.system.service.curingemperature.CuringEmperatureService;

@Tag(name = "管理后台 - 固化温度")
@RestController
@RequestMapping("/system/curing-emperature")
@Validated
public class CuringEmperatureController {

    @Resource
    private CuringEmperatureService curingEmperatureService;

    @PostMapping("/create")
    @Operation(summary = "创建固化温度")
    @PreAuthorize("@ss.hasPermission('system:curing-emperature:create')")
    public CommonResult<Long> createCuringEmperature(@Valid @RequestBody CuringEmperatureSaveReqVO createReqVO) {
        return success(curingEmperatureService.createCuringEmperature(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新固化温度")
    @PreAuthorize("@ss.hasPermission('system:curing-emperature:update')")
    public CommonResult<Boolean> updateCuringEmperature(@Valid @RequestBody CuringEmperatureSaveReqVO updateReqVO) {
        curingEmperatureService.updateCuringEmperature(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除固化温度")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('system:curing-emperature:delete')")
    public CommonResult<Boolean> deleteCuringEmperature(@RequestParam("id") Long id) {
        curingEmperatureService.deleteCuringEmperature(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除固化温度")
                @PreAuthorize("@ss.hasPermission('system:curing-emperature:delete')")
    public CommonResult<Boolean> deleteCuringEmperatureList(@RequestParam("ids") List<Long> ids) {
        curingEmperatureService.deleteCuringEmperatureListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得固化温度")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:curing-emperature:query')")
    public CommonResult<CuringEmperatureRespVO> getCuringEmperature(@RequestParam("id") Long id) {
        CuringEmperatureDO curingEmperature = curingEmperatureService.getCuringEmperature(id);
        return success(BeanUtils.toBean(curingEmperature, CuringEmperatureRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得固化温度分页")
    @PreAuthorize("@ss.hasPermission('system:curing-emperature:query')")
    public CommonResult<PageResult<CuringEmperatureRespVO>> getCuringEmperaturePage(@Valid CuringEmperaturePageReqVO pageReqVO) {
        PageResult<CuringEmperatureDO> pageResult = curingEmperatureService.getCuringEmperaturePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CuringEmperatureRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出固化温度 Excel")
    @PreAuthorize("@ss.hasPermission('system:curing-emperature:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportCuringEmperatureExcel(@Valid CuringEmperaturePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<CuringEmperatureDO> list = curingEmperatureService.getCuringEmperaturePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "固化温度.xls", "数据", CuringEmperatureRespVO.class,
                        BeanUtils.toBean(list, CuringEmperatureRespVO.class));
    }

}